﻿/******************************************************************************
* File description: BoxTimeWaterAirPump.qml
* Function: 主页操作水泵/气泵时弹出来的窗口
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import "../components"

CustomPopupBox {

    id: root

    property int type: 0        // 0水泵 1气泵

    title: type===0 ? "水泵操作" : "气泵开启时长确认"

    height: type===0 ? 255*dp : 210*dp;  width: 380*dp

    function showWaterPump(){
        type = 0
        root.show()
    }
    function showAirPump(){
        type = 1
        root.show()
    }

    contentItem: Item{
        // 上面的输入框
        CustomInputText{        // 仅在气泵时显示
            id: edit_time
            y: 20*dp
            anchors.horizontalCenter: parent.horizontalCenter
            pdouflag: true
            visible: type === 1
            inputMaxLength: 5
            titleWidth: 150*dp
            title: {
                if(type === 0)          return "水泵开启时长(min)"        // 已弃用
                else if(type === 1)     return "气泵开启时长(min)"
            }
        }
        CustomComboBox{         // 仅在水泵时显示
            id: combo_waterPumpState
            anchors.horizontalCenter: parent.horizontalCenter
            y: 20*dp
            visible: root.type===0
            title: "水泵动作"
            titleWidth: 150*dp
            model: ["开", "关"]
        }
        // 下面的输入框
        CustomComboBox{         // 仅在水泵时显示
            id: combo_openN2
            y: 75*dp
            anchors.horizontalCenter: parent.horizontalCenter
            visible: root.type===0
            title: "氦气开关"
            titleWidth: 150*dp
            model: ["开启", "关闭"]
        }
        Row{
            y: type===0 ? 135*dp : 90*dp
            spacing: 15*dp
            anchors.horizontalCenter: parent.horizontalCenter
            CustomButton{
                title: "取消"
                width: 100*dp
                defaultMode2: true
                onClicked: {
                    root.close()
                }
            }CustomButton{
                title: "确定"
                width: 100*dp
                defaultMode1: true
                onClicked: {
                    if(type===1 && (edit_time.getText()==="" || Number(edit_time.getText())===0)){
                        box_error_common.box_text = "请正确填写时长"
                        box_error_common.show()
                        return
                    }
                    if(type === 0){     // 水泵
                        CommunicationMethod.stepOperatingSimulation("2","2",[combo_waterPumpState.getText(), combo_openN2.getText()])

                        // 启动等待小窗口
                        gStateOp.openPopup("23", [])

                        // 加载动画
                        if(combo_waterPumpState.getText() === "开"){
                            CAnimationPractice.openPump1()
                            if(combo_openN2.getText() === "开启"){
                                CAnimationPractice.openPumpHe()
                            }
                        }else if(combo_waterPumpState.getText() === "关"){
                            CAnimationPractice.closePump1()
                            if(combo_openN2.getText() === "开启"){
                                CAnimationPractice.closePumpHe()
                            }
                        }
                    }else if(type === 1){
                        CommunicationMethod.stepOperatingSimulation("2","3",[Number(edit_time.getText())])
                        gStateOp.openPopup("24", [Number(edit_time.getText())])
                        CAnimationPractice.openPump2()
                    }
                    root.close()
                }
            }
        }

    }

}
